package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseAttrInfo;
import com.atguigu.gmall.model.product.BaseCategory1;
import com.atguigu.gmall.model.product.BaseCategory2;
import com.atguigu.gmall.model.product.BaseCategory3;
import com.atguigu.gmall.product.service.BaseAttrInfoService;
import com.atguigu.gmall.product.service.BaseCategory1Service;
import com.atguigu.gmall.product.service.BaseCategoryService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 幼儿猿大班
 * 2021/9/24
 */
@Api("查询分类和平台属性")
@RestController
@RequestMapping("/admin/product")
public class ProductController {

    @Autowired
    BaseCategory1Service baseCategory1Service;

    @Autowired
    BaseCategoryService baseCategoryService;


    @Autowired
    BaseAttrInfoService baseAttrInfoService;

    /**
     * 获取一级分类信息
     * @return
     */
    @GetMapping("getCategory1")
     public Result getCategory1(){
        List<BaseCategory1> category1List = baseCategory1Service.list();

        return Result.ok(category1List);
     }

    /**
     * 根据一级分类id获取二级分类的信息
     * @param category1Id
     * @return
     */
    @GetMapping("getCategory2/{category1Id}")
    public Result getCategory2(@PathVariable("category1Id") Long category1Id){
        List<BaseCategory2> category2List =baseCategoryService.getCategory2ByCategory1Id(category1Id);
        return Result.ok(category2List);
    }


    /**
     * 根据二级分类id获取三级分类的信息
     * @param category2Id
     * @return
     */
    @GetMapping("getCategory3/{category2Id}")
    public Result getCategory3(@PathVariable("category2Id") Long category2Id) {
        List<BaseCategory3> category3List = baseCategoryService.getCategory3ByCateGory2Id(category2Id);
        return Result.ok(category3List);
    }


    /**
     * 获取平台属性
     * @param category1Id  一级分类id
     * @param category2Id  二级分类id
     * @param category3Id  三级分类id
     * @return
     */
    @GetMapping("attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result getattrInfoList(
            @PathVariable("category1Id") Long category1Id,
            @PathVariable("category2Id") Long category2Id,
            @PathVariable("category3Id") Long category3Id) {

         List<BaseAttrInfo> baseAttrInfoList= baseAttrInfoService.getattrInfoList(category1Id,category2Id,category3Id);
         return Result.ok(baseAttrInfoList);

    }

}
